import { request } from '@/utils/request'

/**
 * 获取token
 */
export function oauth(params, success) {
	const headers = {}
	headers['Content-Type'] = 'application/x-www-form-urlencoded';
	headers['Authorization'] = 'Basic d2wtYXBwOjEyMzQ1Ng==';
	return uni.request({
		url: '/cishan-api' + '/oauth/token',
		method: 'post',
		data: params,
		dataType: 'json',
		header: headers,
	}).then(response => {
		const object = response[1];
		if (object.statusCode == 200) {
			const data = object.data;
			if (data.code == '00000') {
				let res = data.data || {};
				res.token = '';
				if(res.access_token != undefined && res.access_token != ''){
				   res.token = res.token_type + ' ' + res.access_token;
				}
				success && success(res);
			}else {
				uni.showToast({
					title: data.msg || '请求失败',
					icon: 'none'
				})
			}
		}
	})
}